package com.li.o2oSystem.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * md5加密工具类
 * @author Administrator
 *
 */
public class MD5 {
	/**
	 * 传入字符串，对字符串进行加密
	 * @param s
	 * @return
	 */
	public static final String getMD5(String s){
		char hexDigits[] = { '5', '0', '5', '6', '2', '9', '6', '2', '5', 'q', 'b', 'l', 'e', 's', 's', 'y' };
		try {
			char str[];
			//将传入的字符串转换为byte数组
			byte strTemp[]  = s.getBytes();
			//获取md5加密对象
			MessageDigest mdTemp = MessageDigest.getInstance("MD5");
			//传入要加密的目标数组
			mdTemp.update(strTemp);
			//获取加密后的数组
			byte md[]  = mdTemp.digest();
			int j = md.length;
			str = new char[j*2];
			int k = 0;
			//将数组做位移
			for(int i = 0;i<j;i++){
				byte byte0 = md[i];
				str[k++] = hexDigits[ byte0 >>> 4 & 0xf];
				str[k++] = hexDigits[byte0 & 0xf];
			}
			return new String(str);
			//转换成String并返回
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return null;
		}
	}
}
